/**
 * Created by 李海强1 on 2016/10/10.
 */
Ext.define('UDZ.controller.Ctr-Main', {
    extend: 'Ext.app.Controller',
    requires: [
        // 'UDZ.model.Model_Regist'
        // 'iconCls'
    ],
    init:function () { //初始化可以加载数据，但不可以对控制件进行操作
      // Ext.getCmp('btn_go').setText('gogogo') ;  //不可行，因为控件还没加载出来
    },
    config: {
        refs: { //关联
                 mainview:{
                     selector:'main',
                     xtype:'main',
                     autoCreate:true
                 },
                myInfoGo:'#personal_myInfo', //关联是通过按钮
                panelHome:'#item01_personal_main',//首页
                panelCloth:'#item03_personal_main',
                // panelPeson:'#item05_personal_main',//个人中心
                user_go_login:'#user_go_login',
                address_manger:'#address_manger',
                UserHeader_go_myinfo:'#UserHeader_go_myinfo',


        },
        control:{  //控制
                  myInfoGo:{
                      initialize:'func_myInfoGo'
                  },
                  panelHome:{
                      activate:'func_active'
                  },
                  panelCloth:{
                      activate:'func_cloth_active'
                  },
                  panelPeson:{
                      activate:'changes' //****
                  },
                 //个人中心去登录
                 user_go_login:{
                     initialize:'func_user_go_login'
                 },
                address_manger:{
                    initialize:'func_addressGo'
                },
                UserHeader_go_myinfo:{
                    initialize:'func_UserHeader_go_myinfo'
                },
        },
        routes: { //自己的路由
            'route_main': 'showMain',
            'route_main_to': 'showMainTo'
        },
    },
    showMain:function () { //
        Ext.Viewport.setActiveItem(this.getMainview()); //直接Viewport进去就行了
    },
    showMainTo:function () { //
        Ext.Viewport.setActiveItem(this.getMainview().setActiveItem(0)); //直接Viewport进去就行了
    },
    func_active:function () {
        // alert(Ext.getCmp("item01_personal_main").iconCls);
        // Ext.getCmp('item01_personal_main').Button({ iconCls : 'icon-add' });
        //****创建个人中心的模版

        var cloth_data={cloth:[  //服装
            {id:1,title:'淘尚优人 秋冬季新款加厚法兰绒卡通动漫女士睡衣 圆领长袖珊瑚绒家居服套装睡衣 格子绒 XL',clothImg:'30.jpg',price:40},
            {id:2,title:'南极人 男士长袖T恤 男秋款2016新修身圆领 长袖体恤青春夏装上衣服 男装 秋 605藏青 180/XL',clothImg:'31.jpg',price:40},
            {id:3,title:'欢乐儿童节',clothImg:'32.jpg',price:40},
            {id:4,title:'北极绒纯棉情侣睡衣秋冬季长袖长裤男女中厚款睡衣家居服棉质套装 可外穿 新款-蓝色条纹情侣款 女M码',clothImg:'33.jpg',price:140},
            {id:5,title:'毕业季',clothImg:'34.jpg',price:40},
            {id:6,title:'南极人 男士长袖T恤 男秋款2016新修身圆领 长袖体恤青春夏装上衣服 男装 秋 605藏青 180/XL',clothImg:'30.jpg',price:40},
            {id:7,title:'欢乐儿童节',clothImg:'31.jpg',price:40},
            {id:8,title:'南极人 男士长袖T恤 男秋款2016新修身圆领 长袖体恤青春夏装上衣服 男装 秋 605藏青 180/XL',clothImg:'32.jpg',price:180}
        ]};
        var cloth_tpl=new Ext.XTemplate(
            '<div class="cloth_big_container">' +
            '<tpl for="cloth">' +
            '<div class="cloth_img_container">' +
            '<img  src="resources/images/{clothImg}"  onclick="location.href=\'#route_cloth_detail/{id}\';">'+
                '<hr style="border:0px;display: inline-block;width:100%;position: relative;top:10px">'+
            '<div class="cloth_name_container" onclick="location.href=\'#route_cloth_detail/{id}\';">' +
            '<span >{title:ellipsis(20)}</span><span class="lnr-heart"></span>' +
            '</div>'+
             '<div class="cloth_price_container" onclick="location.href=\'#route_cloth_detail/{id}\';">' +
            '<span ></span>￥{price}<span class="lnr-heart"></span>' +
            '</div>'+
            '</div>' +
            '</tpl>'+
            '</div>'
        );
        var  cloth_content=cloth_tpl.apply(cloth_data);
        Ext.getCmp('home_cloth_panel').setHtml( cloth_content);

        //1准备数据
        var theme_data={theme:[  //主题
            {title:'毕业季',con:'长亭外，古道边，芳草碧连天。唱到一半，就已泪流满面。毕业了，面对那些爱情，友情，还有眷恋的 校园，你是不是还有很多的话要说',themeImg:'001.jpg'},
            {title:'开学那点事',con:'你上，或者不上学，学校就在那里，按时开学。你念，或者不念书，书就在那里，早晚得念。你 听，或者不听课，老师就在那里，不下课不走。你学',themeImg:'002.jpg'},
            {title:'欢乐儿童节',con:'迎接儿童节回归童心，卡通人物图案大推荐。每个童年都有一个美好的梦想，我们都会描绘着心中 的向往，每个小孩都是精灵都是天使，都有出人意料的想像和艺术感受力，在这个属于孩子们的节日里，为他定制一件他喜欢的T恤穿上身吧！',themeImg:'003.jpg'},
            {title:'情人节专题',con:'爱情是人类社会永恒的主题，她需要用心经营，更需要通过手段表示。情侣装不单单是两件一样的 衣服，更能促进情侣之间的感情交流。',themeImg:'004.jpg'}
        ]};
        //2准备显示模版
        var theme_tpl=new Ext.XTemplate(
            '<tpl for="theme">' +
            '<div class="theme_container">'+
               '<div class="img_container">' +
                 '<img src="resources/images/{themeImg}">' +
               '</div>' +
                '<div class="theme_content_container">' +
            // '<div>{#}</div>' + //1 2 3 4 5
                  '<div class="theme_title">{title}</div>' +
                  '<div class="theme_con">{con:ellipsis(25)}</div>' +  //****
                  '<div class="theme_look_more">查看详情</div>'+
               '</div>' +
            '</div>' +
            '</tpl>'
        );

        //3
        var content= theme_tpl.apply(theme_data);
        //写入
        Ext.getCmp('home_theme_panel').setHtml(content);


      //印花
        var printing_data={printing:[
            {title:'毕业季',printingImg:'20.png'},
            {title:'开学那点事',printingImg:'21.png'},
            {title:'欢乐儿童节',printingImg:'22.png'},
            {title:'情人节专题',printingImg:'23.png'},
            {title:'毕业季',printingImg:'24.png'},
            {title:'开学那点事',printingImg:'25.png'},
            {title:'欢乐儿童节',printingImg:'26.png'},
            {title:'情人节专题',printingImg:'27.png'}
        ]};
        var printing_tpl=new Ext.XTemplate(
            '<div class="printing_big_container">' +
            '<tpl for="printing">' +
               '<div class="printing_img_container">' +
                 '<img src="resources/images/{printingImg}">'+
                     '<div class="printing_like_container">' +
                        '<span class="printing_like_title">{title:ellipsis(10)}</span><span class="heart"></span>' +
                     '</div>'+
                  '</div>' +
            '</tpl>'+
        '</div>'
        );
        var  printing_content= printing_tpl.apply(printing_data);
        Ext.getCmp('home_printing_panel').setHtml(printing_content);

    },
         //    服装
    func_cloth_active:function () {

        var cloth_main_data={clothing:[
            {
                 cloth: '男装', clothName: [
                {name: '连帽卫衣',imgContent:[
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '32.jpg', clothTitle: '南极人',price: 35},
                    {Img: '33.jpg', clothTitle: '南极人',price: 35},
                    {Img: '34.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '32.jpg', clothTitle: '南极人',price: 35}
                    ]
                },
                {name: '圆角卫衣',imgContent:[
                    {Img: '32.jpg', clothTitle: '南极人',price: 35},
                    {Img: '33.jpg', clothTitle: '南极人',price: 35},
                    {Img: '34.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35}
                ]},
                {name: 'T恤', imgContent:[
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35}
                 ]},
                {name: '卫衣', imgContent:[
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35},
                    {Img: '30.jpg', clothTitle: '南极人',price: 35}
                    ]}
              ]
            },
            {
                cloth: '女装', clothName: [
                    {name: '连帽卫衣',imgContent:[
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35}
                    ]},
                    {name: '圆角卫衣',imgContent:[
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35}
                    ]},
                    {name: 'T恤',imgContent:[
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35}
                    ]},
                    {name: '卫衣',imgContent:[
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35},
                        {Img: '34.jpg', clothTitle: '南极人',price: 35}
                    ]}
                ]
            },  {
                cloth: '团体装', clothName: [
                    {name: '连帽卫衣'},
                    {name: '圆角卫衣'},
                    {name: 'T恤'},
                    {name: '卫衣'}
                ]
            },
            {
                cloth: '童装', clothName: [
                    {name: '连帽卫衣'},
                    {name: '圆角卫衣'},
                    {name: 'T恤'},
                    {name: '卫衣'}
                ]
            }
        ]}
        var cloth_main_tpl=new Ext.XTemplate(
            '<tpl for="clothing">' +
                  '<p class="border">{cloth}</p>'+
            '</tpl>'
        );
        var cloth_main_content= cloth_main_tpl.apply(cloth_main_data);
        Ext.getCmp('my_cloth').setHtml(cloth_main_content);


        var cloth_main_name_tpl=new Ext.XTemplate(
          '<div class="mycloth_big_container">' +
            '<tpl for="clothing">'+
               '<tpl for="clothName">' +
                '<div class="mycloth_name"><p>{name}</p></div>'+
                '<div class="imgContent"><tpl for="imgContent">'+
                     '<div class="mycloth_img_container">' +
                       '<img  src="resources/images/{Img}">'+
                       '<hr  style="border:0px;display: inline-block;width:100%;position: relative;top:0px">'+
                       '<div class="mycloth_name_container">' +
                       '<span >{clothTitle:ellipsis(20)}</span>'+
                       '</div>'+
                    '<div class="mycloth_price_container">' +
                    '<span ></span>￥{price}<span class="lnr-heart"></span>' +
                    '</div>'+
                '</div>'+
            '</tpl></div>'+
            '</tpl>'+
            '</tpl>'+
            '</div>'

        );
        var cloth_main_name_content= cloth_main_name_tpl.apply(cloth_main_data);
        Ext.getCmp('my_cloth_name').setHtml(cloth_main_name_content);
    },

    func_myInfoGo:function () { //方法
        var me=this;
        Ext.getCmp('personal_myInfo').element.on({
            tap : function( ) { //点击事件
                me.redirectTo('route_myinfo');
            },
            swipe : function(e, target, options, eOpts ) { //滑动监听
                if (e.direction === 'left' && e.distance >= 10) {
                    me.redirectTo('route_myinfo');
                } else if (e.direction === 'right' && e.distance >= 20) {
                    me.redirectTo('route_myinfo_to');
                }
            }
        });
    },
    func_UserHeader_go_myinfo:function () { //方法
        var me=this;
        Ext.getCmp('UserHeader_go_myinfo').element.on({
            tap : function( ) { //点击事件
                me.redirectTo('route_myinfo');
            },
            swipe : function(e, target, options, eOpts ) { //滑动监听
                if (e.direction === 'left' && e.distance >= 10) {
                    me.redirectTo('route_myinfo');
                } else if (e.direction === 'right' && e.distance >= 20) {
                    me.redirectTo('route_myinfo_to');
                }
            }
        });
    },
    //收货地址
    func_addressGo:function () {
        var me=this;
        Ext.getCmp('address_manger').element.on({
            tap : function( ) {
                me.redirectTo('route_address_manger');
            },
            swipe : function(e, target, options, eOpts ) { //滑动监听
                if (e.direction === 'left' && e.distance >= 20) {
                    me.redirectTo('route_address_manger');
                } else if (e.direction === 'right' && e.distance >= 20) {
                    me.redirectTo('route_address_manger');
                }
            }
        });
    },

    //个人中心
    // changes:function () {
    //
    //     //****创建个人中心的模版
    //     //1准备数据
    //     var data={article:[
    //         {title:'xtemplate',time:'9:40'},
    //         {title:'xtemplate',time:'9:40'},
    //         {title:'xtemplate',time:'9:40'},
    //         {title:'xtemplate',time:'9:40'},
    //         {title:'xtemplate',time:'9:40'}
    //     ]};
    //     //2准备显示模版
    //     var tpl=new Ext.XTemplate(
    //         '<tpl for="article">' +
    //         '<div class="article_container">' +
    //         '<div class="img_container">' +
    //         '<img src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=737800911,2352268185&fm=116&gp=0.jpg">' +
    //         '</div>' +
    //         '<div class="content_container">' +
    //         '<div>{#}</div>' + //1 2 3 4 5
    //         '<div>{title}</div>' +
    //         '<div>{time}</div>' +
    //         '</div>' +
    //         '</div>' +
    //         '</tpl>'
    //     );
    //     //3
    //     var content= tpl.apply(data);
    //     //写入
    //     // Ext.getCmp('personal_panel').setHtml(content);
    // },
    func_user_go_login:function () { //方法
        var me=this;
        Ext.getCmp('user_go_login').element.on({
            tap : function( ) { //点击事件
                me.redirectTo('route_Login');
            },
            swipe : function(e, target, options, eOpts ) { //滑动监听
                if (e.direction === 'left' && e.distance >= 20) {
                    me.redirectTo('route_Login');
                } else if (e.direction === 'right' && e.distance >= 20) {
                    me.redirectTo('route_Login');
                }
            }
        });
    },
});